import request from '../utils/request';

// 企业端需求管理API
export const enterpriseApi = {
  // 获取需求列表
  getDemands: (params = {}) => {
    return request.get('/api/api/v1/enterprise/demands', { params });
  },

  // 获取需求详情（管理端）
  getDemandDetailForManage: (demandId) => {
    return request.get(`/api/api/v1/enterprise/demand/manage/detail/${demandId}`);
  },

  // 获取需求详情（公开端）
  getDemandDetail: (demandId) => {
    return request.get(`/api/api/v1/enterprise/demand/detail/${demandId}`);
  },

  // 创建需求
  createDemand: (data) => {
    return request.post('/api/api/v1/enterprise/demands', data);
  },

  // 更新需求
  updateDemand: (demandId, data) => {
    return request.put(`/api/api/v1/enterprise/demands/${demandId}`, data);
  },

  // 保存草稿
  saveDraft: (data) => {
    return request.post('/api/api/v1/enterprise/demands/draft', data);
  },

  // 更新草稿
  updateDraft: (demandId, data) => {
    return request.put(`/api/api/v1/enterprise/demands/${demandId}/draft`, data);
  },

  // 提交审核
  submitDemand: (demandId) => {
    return request.post(`/api/api/v1/enterprise/demands/${demandId}/submit`);
  },

  // 获取需求状态
  getDemandStatus: (demandId) => {
    return request.get(`/api/api/v1/enterprise/demands/${demandId}/status`);
  },

  // 获取需求统计
  getDemandStats: () => {
    return request.get('/api/api/v1/enterprise/demands/stats');
  },

  // 获取需求模板
  getDemandTemplates: () => {
    return request.get('/api/api/v1/enterprise/demands/templates');
  },

  // 复制需求
  copyDemand: (demandId) => {
    return request.post(`/api/api/v1/enterprise/demands/${demandId}/copy`);
  },

  // 批量操作
  batchOperation: (operation, demandIds) => {
    return request.post('/api/api/v1/enterprise/demands/batch', {
      operation,
      demandIds
    });
  },

  // 获取国家列表
  getCountries: () => {
    return request.get(`/api/api/v1/enterprise/demands/countries`)
  },

  // 获取城市列表
  getCities: (countryId) => {
    return request.get(`/api/api/v1/enterprise/demands/cities`, {
      params: { countryId }
    })
  },

  // 发布需求
  publishDemand: (data) => {
    return request.post('/api/api/v1/enterprise/demands/publish', data)
  },

  // 获取需求管理列表（支持状态筛选）
  getDemandManageList: (params = {}) => {
    return request.get('/api/api/v1/enterprise/demand/manage/list', { 
      params: { 
        page: params.page || 1, 
        pageSize: params.pageSize || 10,
        status: params.status || ''
      } 
    })
  },

  // 获取企业用户的所有需求列表（支持状态筛选）
  getEnterpriseDemands: (params = {}) => {
    return request.get('/api/api/v1/enterprise/demand/manage/all', { 
      params: { 
        page: params.page || 1, 
        pageSize: params.pageSize || 10,
        status: params.status || ''
      } 
    })
  },

  // 编辑需求
  editDemand: (demandId, data) => {
    return request.put(`/api/api/v1/enterprise/demand/manage/edit/${demandId}`, data)
  },

  // 获取需求详情
  getDemandDetail: (demandId) => {
    return request.get(`/api/api/v1/enterprise/demand/manage/detail/${demandId}`)
  },

  // 下线需求
  offlineDemand: (demandId) => {
    return request.put(`/api/api/v1/enterprise/demand/manage/offline/${demandId}`)
  },

  // 上线需求
  onlineDemand: (demandId) => {
    return request.put(`/api/api/v1/enterprise/demand/manage/online/${demandId}`)
  },

  // 曝光需求
  exposeDemand: (demandId) => {
    return request.put(`/api/api/v1/enterprise/demand/manage/expose/${demandId}`)
  },

  // 下架需求
  closeDemand: (demandId) => {
    return request.put(`/api/api/v1/enterprise/demand/manage/offline/${demandId}`)
  },

  // 重新开启需求
  reopenDemand: (demandId) => {
    return request.put(`/api/api/v1/enterprise/demand/manage/online/${demandId}`)
  },
};

// 需求类型常量
export const DEMAND_TYPES = {
  RECRUITMENT: 'talent', // 人才招聘
  TRADE: 'trade' // 贸易合作
};

// 需求状态常量
export const DEMAND_STATUS = {
  DRAFT: 'draft', // 草稿
  PENDING_REVIEW: 'pending_review', // 待审核
  APPROVED: 'approved', // 已通过
  REJECTED: 'rejected', // 已拒绝
  PUBLISHED: 'published', // 已发布
  CLOSED: 'closed', // 已关闭
  EXPIRED: 'expired' // 已过期
};

// 职位类型常量
export const JOB_TYPES = {
  FULL_TIME: 'full_time', // 全职
  PART_TIME: 'part_time', // 兼职
  INTERNSHIP: 'internship', // 实习
  PROJECT_BASED: 'project_based' // 项目制
};

// 学历要求常量
export const EDUCATION_LEVELS = {
  HIGH_SCHOOL: 'high_school', // 高中
  COLLEGE: 'college', // 大专
  BACHELOR: 'bachelor', // 本科
  MASTER: 'master', // 硕士
  DOCTOR: 'doctor' // 博士
}; 

// 企业消息管理API - 基于 EnterpriseCertificationController
export const enterpriseMessageApi = {
  // ==================== 消息基础操作 ====================
  
  // 获取企业用户的消息列表
  getMessages: (params = {}) => {
    return request.get('/api/api/v1/enterprise/certification/messages', { 
      params: {
        page: params.page || 1,
        size: params.size || 10,
        messageType: params.messageType || ''
      }
    });
  },

  // 获取消息详情
  getMessageDetail: (messageId) => {
    return request.get(`/api/api/v1/enterprise/certification/messages/${messageId}`);
  },

  // 标记消息为已读
  markMessageAsRead: (messageId) => {
    return request.put(`/api/api/v1/enterprise/certification/messages/${messageId}/read`);
  },

  // 标记所有消息为已读
  markAllMessagesAsRead: () => {
    return request.put('/api/api/v1/enterprise/certification/messages/mark-all-read');
  },

  // 标记消息为未读
  markMessageAsUnread: (messageId) => {
    return request.put(`/api/api/v1/enterprise/certification/messages/${messageId}/unread`);
  },

  // ==================== 消息状态管理 ====================
  
  // 获取未读消息数量
  getUnreadCount: () => {
    return request.get('/api/api/v1/enterprise/certification/messages/unread-count');
  },

  // 获取消息统计信息
  getMessageStatistics: () => {
    return request.get('/api/api/v1/enterprise/certification/messages/statistics');
  },

  // 获取支持的消息类型列表
  getMessageTypes: () => {
    return request.get('/api/api/v1/enterprise/certification/messages/types');
  },

  // ==================== 消息高级操作 ====================
  
  // 刷新企业用户消息列表
  refreshMessages: () => {
    return request.post('/api/api/v1/enterprise/certification/messages/refresh');
  },

  // 删除单条消息
  deleteMessage: (messageId) => {
    return request.delete(`/api/api/v1/enterprise/certification/messages/${messageId}`);
  },

  // 批量删除消息
  batchDeleteMessages: (messageIds) => {
    return request.post('/api/api/v1/enterprise/certification/messages/batch-delete', {
      messageIds: messageIds
    });
  },

  // 清空所有消息
  clearAllMessages: () => {
    return request.delete('/api/api/v1/enterprise/certification/messages/clear-all');
  },

  // ==================== 消息分类管理 ====================
  
  // 获取消息分类统计
  getMessageCategoryStats: () => {
    return request.get('/api/api/v1/enterprise/certification/messages/category-stats');
  },

  // 设置消息分类偏好
  setMessagePreferences: (preferences) => {
    return request.post('/api/api/v1/enterprise/certification/messages/preferences', preferences);
  },

  // 获取消息偏好设置
  getMessagePreferences: () => {
    return request.get('/api/api/v1/enterprise/certification/messages/preferences');
  }
};

// 企业消息类型枚举
export const MESSAGE_TYPES = {
  ENTERPRISE_CERTIFICATION: 'enterprise_certification', // 企业认证相关
  ENTERPRISE_CONTACT: 'enterprise_contact', // 企业联系相关
  DEMAND_REVIEW: 'demand_review', // 需求审核相关
  MATCHING_SUCCESS: 'matching_success', // 匹配成功通知
  ACCOUNT_DISABLED: 'account_disabled', // 账户状态变更
  PASSWORD_CHANGE: 'password_change' // 密码变更通知
};

// 消息状态常量
export const MESSAGE_STATUS = {
  UNREAD: 'unread', // 未读
  READ: 'read', // 已读
  ARCHIVED: 'archived', // 已归档
  DELETED: 'deleted', // 已删除
  PINNED: 'pinned' // 已置顶
};

// 消息优先级常量
export const MESSAGE_PRIORITY = {
  LOW: 'low', // 低优先级
  NORMAL: 'normal', // 普通优先级
  HIGH: 'high', // 高优先级
  URGENT: 'urgent' // 紧急
}; 